<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="手机号" prop="userMobile">
        <el-input
          v-model="queryParams.userMobile"
          placeholder="请输入手机号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单编号" prop="busid">
        <el-input
          v-model="queryParams.busid"
          placeholder="请输入订单编号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="orderList">
      <el-table-column
        label="用户id"
        align="center"
        prop="userId"
        width="190"
      />
      <el-table-column label="用户名称" align="center" prop="nickName" />
      <el-table-column label="手机号" align="center" prop="mobile" />
      <el-table-column label="操作后金额" align="center" prop="lastMoney" />
      <el-table-column label="充值金额" align="center" prop="money" />
      <el-table-column
        label="充值凭证"
        align="center"
        prop="certificateUrls"
        width="320"
      >
        <template slot-scope="scope">
          <div style="flex">
            <el-image
              v-for="(item, index) in scope.row.certificateUrls"
              :key="index"
              :src="item"
              :preview-src-list="[item]"
              class="imagesss"
            ></el-image>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="state">
        <template slot-scope="scope">
          <span v-if="scope.row.state == 0">待审核</span>
          <span v-if="scope.row.state == 1">审核通过</span>
          <span v-if="scope.row.state == 2">审核驳回</span>
        </template>
      </el-table-column>
      <el-table-column label="用户备注" align="center" prop="remark" />
      <el-table-column label="审核备注" align="center" prop="auditRemarks" />
      <el-table-column label="审核时间" align="center" prop="updateTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="160"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <div>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-check"
              v-if="scope.row.state == 0"
              @click="handleAudit(scope.row)"
              >审核</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 审核 -->
    <el-dialog
      title="充值审核"
      :visible.sync="open"
      width="500px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="充值用户">
          <el-input v-model="form.nickName" placeholder="充值用户" disabled />
        </el-form-item>
        <el-form-item label="充值金额">
          <el-input v-model="form.money" placeholder="充值金额" disabled />
        </el-form-item>
        <el-form-item label="审核状态" prop="state">
          <el-radio-group v-model="form.state">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核备注" v-if="form.state === 2">
          <el-input
            v-model="form.auditRemarks"
            type="textarea"
            :maxlength="50"
            placeholder="请输入审核备注"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  insertCate,
  detailCate,
  modifyCate,
  delCate,
} from "@/api/product/productCate";
import { userBalanceData, balanceAudit } from "@/api/customer/customer";
import { getSassToken } from "@/utils/utils";
import { Debounce } from "@/utils/tools.js";
import imageDrapUpload from "@/components/Upload";
export default {
  name: "productCate",
  components: {
    imageDrapUpload,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      typeList: [],
      // 弹出层标题
      title: "订单发货",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        userMobile: "",
        busid: "",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        state: [
          { required: true, message: "请选择审核状态", trigger: "change" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      userBalanceData(this.queryParams).then((response) => {
        this.orderList = response.data;
        this.total = response.extend.total;
        this.loading = false;
      });
    },
    // 审核按钮
    handleAudit(data) {
      this.form = JSON.parse(JSON.stringify(data));
      this.open = true;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商品分类";
    },
    /** 删除按钮操作 */
    handleDelete: Debounce(function (row) {
      this.$modal
        .confirm('是否确认删除名称为"' + row.cateName + '"的数据项？')
        .then(function () {
          return delCate(row.cateId);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    }, 500),
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleUpdate: Debounce(function (row) {
      this.reset();
      detailCate(row.cateId).then((response) => {
        if (response.code === 200) {
          if (response.data && response.data.cateIcon) {
            response.data.cateIcon = [{ url: response.data.cateIcon }];
          }
          this.form = response.data;
          this.open = true;
          this.title = "修改商品分类";
        }
      });
    }, 500),
    /** 审核提交按钮 */
    submitForm: Debounce(function (row) {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          let data = {
            id: this.form.id,
            state: this.form.state,
            auditRemarks: this.form.auditRemarks,
          };
          balanceAudit(data).then((response) => {
            this.$modal.msgSuccess("审核操作成功");
            this.open = false;
            this.form = {};
            this.getList();
          });
        }
      });
    }, 500),
  },
};
</script>
<style lang="scss" scoped>
.imagesss {
  width: 60px;
  height: 60px;
  margin-right: 5px;
}
</style>
